<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>代驾订单详情页</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!-- 样式 -->
    <link rel="stylesheet" href="../../css/style.css"/>
    <!-- 主题（主要颜色设置） -->
    <link rel="stylesheet" href="../../css/theme.css"/>
    <!-- 通用的css -->
    <link rel="stylesheet" href="../../css/common.css"/>
    <link rel="stylesheet" href="../../xznstatic/css/bootstrap.min.css">
</head>
<style>
</style>
<body>

    <div id="app">
    </div>


    <script src="../../layui/layui.js"></script>
    <script src="../../js/vue.js"></script>
    <!-- 引入element组件库 -->
    <script src="../../xznstatic/js/element.min.js"></script>
    <!-- 引入element样式 -->
    <link rel="stylesheet" href="../../xznstatic/css/element.min.css">
    <!-- 组件配置信息 -->
    <script src="../../js/config.js"></script>
    <!-- 扩展插件配置信息 -->
    <script src="../../modules/config.js"></script>
    <!-- 工具方法 -->
    <script src="../../js/utils.js"></script>

    <script>
        Vue.prototype.myFilters= function (msg) {
            if(msg != null){
                return msg.replace(/\n/g, "<br>");
            }else{
                return "";
            }
        };
        var vue = new Vue({
            el: '#app',
            data: {
                //当前登录用户信息
                user:{},
                // 轮播图
                swiperList: [],//用于当前表的图片
                // 数据详情
                detail: {
                    id: 0
                },
                // 商品标题
                title: '',
                totalScore: 0,//评分
                baseUrl:"",//路径
                storeupFlag: 0,//收藏 [0为收藏 1已收藏]
                //系统推荐
                daijiaDingdanRecommendList: [],
                    // 当前详情页表
                detailTable: 'daijiaDingdan',
                // 评价列表
                daijiaDingdanCommentbackDataList: [],
            },
            methods: {
            //咨询问题
            zixunwenti() {
                let _this = this
                layui.layer.open({
                    type: 2,
                    title: '咨询',
                    area: ['600px', '600px'],
                    content: '../daijiaDingdanChat/list.html?sijiId='+_this.detail.sijiId
                });
            },                //分享
                share(){
                    let element = createElement("http://localhost:8080/daijiaguanli/front/index.html?url="+"./pages/daijiaDingdan/detail.html?id="+this.id);
                    element.select();
                    element.setSelectionRange(0, element.value.length);
                    document.execCommand('copy');
                    element.remove();
                    layui.layer.msg('复制分享页面成功,快去分享吧!', {time: 2000,icon: 6});
                },

                jump(url) {
                    jump(url)
                },
                isAuth(tablename, button) {
                    return isFrontAuth(tablename, button)
                },
                //预约
                daijiaDingdanYuyue(){
                    let _this = this;
                    var mymessage = confirm("确定要预约吗？");if(!mymessage){return false;}
                    // localStorage.setItem('daijiaDingdanId', _this.detail.id);
                    // _this.jump("../daijiaDingdanOrder/add.html");

                    let data={
                        daijiaDingdanId:_this.detail.id,
                        yonghuId:localStorage.getItem("userid"),
                        daijiaDingdanOrderYesnoTypes:1,
                    }
                    // 提交数据
                    layui.http.requestJson('daijiaDingdanOrder/add', 'post', data, function (res) {
                        if(res.code == 0) {
                            layui.layer.msg('预约成功', {
                                time: 2000,
                                icon: 6
                            }, function () {
                                _this.jump("../daijiaDingdanOrder/list.html");
                            });
                        }else{
                            layui.layer.msg(res.msg, {
                                time: 5000,
                                icon: 5
                            });
                        }
                    });
                },

                }
        });

        layui.use(['layer', 'form', 'element', 'carousel', 'http', 'jquery', 'laypage', 'util'], function () {
            var layer = layui.layer;
            var util = layui.util;
            var element = layui.element;
            var form = layui.form;
            var carousel = layui.carousel;
            var http = layui.http;
            var jquery = layui.jquery;
            var laypage = layui.laypage;
            vue.baseUrl = http.baseurl

            localStorage.setItem("goUtl","./pages/daijiaDingdan/detail.html?id="+ http.getParam('id'))

            var limit = 10;

            let table = localStorage.getItem("userTable");
            if(table){
                http.request(table+"/session", 'get', {}, function (data) {
                    vue.user = data.data;
                });
            }

            // 数据ID
            var id = http.getParam('id');
            vue.detail.id = id;

                /*
					 tableName 查询表
				     condition1 条件1
				     condition1Value 条件1值
				     average 计算平均评分
				* */
            http.request(`queryScore`, 'get', {
                tableName: 'daijia_dingdan_commentback',
                average: 'daijia_dingdan_commentback_pingfen_number',
                condition1: 'daijia_dingdan_id',
                condition1Value: vue.detail.id,
            }, function(res) {
                if (res.data) {
                    vue.totalScore = Number(res.data.value.toFixed(1));
                } else {
                    vue.totalScore = 0
                }
            });

            // 获取评价
            http.request(`${vue.detailTable}Commentback/list`, 'get', {
                page: 1,
                limit: limit,
                daijiaDingdanId: vue.detail.id
            }, function (res) {
                vue.daijiaDingdanCommentbackDataList = res.data.list;
                // 分页
                laypage.render({
                    elem: 'LiuyanPager',
                    count: res.data.total,
                    limit: limit,
                    jump: function (obj, first) {
                        //首次不执行
                        if (!first) {
                            http.request(`${vue.detailTable}Commentback/list`, 'get', {
                                page: obj.curr,
                                limit: obj.limit,
                                daijiaDingdanId: vue.detail.id
                            }, function (res) {
                                vue.daijiaDingdanCommentbackDataList = res.data.list
                            })
                        }
                    }
                });
            });
        });
    </script>
</body>
</html>
